/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ericsson.nfc.signing.algorithm;

import java.security.MessageDigest;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;

/**
 *
 * @author emarkki
 */
public class DigestFactory {

    public static Digest getDigest(String algorithm) {
        Digest d = null;
        
        if("SHA-1".equals(algorithm)) {
            if(ImplementationDetector.getInstance().isSatsaAvailable()) {
                MessageDigest md = null;
                try {
                    md = MessageDigest.getInstance("SHA-1");
                } catch(Exception ex) {}
                
                if(md != null) {
                    d = new SatsaSha1Digest(md);
                }
            }
            
            if(d == null) {
                d = new SHA1Digest();
            }
        }
        
        return d;
    }
    
}
